var rotate = function(nums, k) {
    let len = nums.length;
    k = k % len;
    reverse(nums,0,len-1);
    reverse(nums,0,k-1);
    reverse(nums,k,len-1);
};

function reverse(arr,start,end){
    while(start < end){
        [arr[start],arr[end]] = [arr[end],arr[start]];
        end--;
        start++;
    }
}

var attr=[1, 2, 3, 4, 5, 6, 7]
rotate(attr, 2)

console.log(attr)